package chordrouting;

import java.util.LinkedHashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-09-29
 * Time: 11:52
 */
public class Node {
    private int value;
    private LinkedHashMap<Integer, Node> fingerTable;
    private LinkedHashMap<Object, Object> keyValueMap = new LinkedHashMap<>();

    @Override
    public String toString() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("nodeName: ").append(getNodeName()).append("\n");
        stringBuffer.append("fingerTable: \n");
        for (Integer index : fingerTable.keySet()) {
            stringBuffer.append("\t").append(getNodeName()).append("+").append(index).append(" -> ").append(fingerTable.get(index).getNodeName()).append("\n");
        }
        stringBuffer.append("key-value: \n");
        for (Object key : keyValueMap.keySet()) {
            stringBuffer.append("\t").append(key).append(" -> ").append(keyValueMap.get(key)).append("\n");
        }
        return stringBuffer.toString();
    }

    public Object putKeyValue(Object key,Object value) {
        return keyValueMap.put(key, value);
    }

    public Object getKeyValue(Object key) {
        return keyValueMap.get(key);
    }

    public Object removeKeyValue(Object key) {
        return keyValueMap.remove(key);
    }

    public LinkedHashMap<Object, Object> getKeyValueMap() {
        return keyValueMap;
    }

    public void clearKeyValue() {
        keyValueMap.clear();
    }

    public String getNodeName() {
        return "N" + value;
    }

    public Node(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public LinkedHashMap<Integer, Node> getFingerTable() {
        return fingerTable;
    }

    public void setFingerTable(LinkedHashMap <Integer, Node> fingerTable) {
        this.fingerTable = fingerTable;
    }
}
